// pages/accidentReport/reportOrderSelect/index.js
import urls from '../../../requestUrl'
import request from '../../../baseRequest'
Page({
  /**
   * 页面的初始数据
   */
  data: {
    tabs: [],
    currentType: 'hwx',
    hwxOrder: [],
    ckxOrder: [],
    sjxOrder: []
  },
  /**切换订单类型 */
  handleTypeChange(e) {
    this.setData({
      currentType: e.detail.key
    })
   this.getInsuranceOrderList(e.detail.key)
  },
  /**选中具体的表单项 */
  handleOnSelectItem(e) {
    let targetOrderId = e.detail
    console.log(e)
    wx.navigateTo({
      url: `/pages/accidentReport/reportCreate/index?orderid=${targetOrderId}`,
    })
  },
  /**获取服务订单列表(仅查询出正在进行中的服务订单，可一次请求所有数据)
   */
  getInsuranceOrderList(type) {

    let param = {
      "insuranceClassifyId": this.getInsuranceTypeId(type),
      "openid": this.data.openid,
      "orderStatusList": ['4']
    }
    request.postRequest(urls.insurance.listOrder, param, (res) => {
      if (type == "hwx") {
        this.setData({
          hwxOrder: res.list
        })
      } else if(type == "ckx") {
        this.setData({
          ckxOrder: res.list
        })
      } else {
        this.setData({
          sjxOrder: res.list
        })
      }

    }, () => { })


  },

  getInsuranceTypeId(key) {
    let p = this.data.tabs.find((item) => item.key === key)
    return p.id
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let tabs = getApp().globalData.insuranceTypes
    this.data.openid=getApp().getUserOpenid()
    this.setData({
      tabs
    })
    this.getInsuranceOrderList(this.data.currentType)
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})
